package com.mobi.Survey.lib.uicomponents;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RatingBar;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;

import com.mobi.Survey.lib.model.SurveyDetailPojo;
import com.mobi.Survey.lib.utils.Helper;

/**
 * 
 * <p>
 * <b>Author:</b> Yahya Arshad
 * <p>
 * <b>Company:</b> Mobi Media Soft
 * <p>
 * <b> Website:</b> www.mobimediasoft.com
 * <p>
 * CustomRatingBar.java
 * 
 * 
 */
public class CustomRatingBar extends RatingBar
{
	private Context ctx;
	private LinearLayout ll;

	public CustomRatingBar(Context context, SurveyDetailPojo sdp,
			boolean editable)
	{
		super(context);
		this.ctx = context;
		ll = new LinearLayout(ctx);
		RelativeLayout.LayoutParams param = new LayoutParams(
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

		ll.setLayoutParams(param);
		ll.setOrientation(LinearLayout.VERTICAL);

		if (sdp.getControlText() != null && sdp.getControlText().length() > 0)
		{

			CustomTextView ctv = new CustomTextView(ctx);
			ctv.setCustomColor(sdp);
			ctv.setText(sdp.getControlText());
			LinearLayout.LayoutParams par = new LinearLayout.LayoutParams(
					LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
			ctv.setLayoutParams(par);

			ll.addView(ctv);

		}
		int starts = Helper.toInt(sdp.getControlParameter1());
		this.setNumStars(starts);
		this.setRating(Helper.toFloat(sdp.getUserValue()));
		LinearLayout.LayoutParams par = new LinearLayout.LayoutParams(
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		this.setLayoutParams(par);
		this.setStepSize(1);
		// this.setRating(2);
		this.setStepSize(.5f);
		if (!editable)
			this.setEnabled(false);
		ll.addView(this);

	}

	// public void setRating(float rating) {
	// this.setRating(rating);
	// }

	public View getView()
	{
		return ll;
	}

}
